package com.speedchina.permission.web.message;
import com.speedchina.common.message.util.SendResult;
import com.speedchina.common.message.wechat.message.*;
import com.speedchina.common.message.wechat.service.WechatService;
import com.speedchina.common.message.wechat.util.Base64Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;

@RestController
public class MessageController {

    @Autowired
    WechatService wechatService;

    /**
     * 测试文本类型 content 必填
     * @return
     */
    @RequestMapping("/SEND")
    public SendResult ss(){
        System.err.println(Thread.currentThread().getName());
        TextMessage textMessage = new TextMessage();
        textMessage.setText("注解进行默认url测试");
        textMessage.setAtAll(true);
        SendResult sendResult = wechatService.send(textMessage);
        return sendResult;
    }
    /**
     * 测试文本类型 content 必填
     * @return
     */
    @RequestMapping("/SEND88")
    public SendResult ss888(){
        System.err.println(Thread.currentThread().getName());
        TextMessage textMessage = new TextMessage();
        textMessage.setText("测试注解形式8888");
        textMessage.setAtAll(true);
        SendResult sendResult = wechatService.send(textMessage);
        return sendResult;
    }
    @RequestMapping("/SEND1")
    public SendResult ss1(){
        NewsMessage newsMessage = new NewsMessage();

        NewsArticle newsArticle = new NewsArticle();
        newsArticle.setTitle("多群发送测试");
        newsArticle.setDescription("多群发送测试");
        newsArticle.setUrl("www.baidu.com");
        newsArticle.setPicurl("https://img1.baidu.com/it/u=3085024711,1522297612&fm=11&fmt=auto&gp=0.jpg");

        NewsArticle article=new NewsArticle();
        article.setTitle("多群发送测试");
        article.setDescription("有我提醒多群发送");
        article.setUrl("http://106.14.161.77:8080/login/Login.jsp?gopage=&_rnd_=c62c20df-7949-46d7-be61-85b657456ef4");
        article.setPicurl("https://img1.baidu.com/it/u=3085024711,1522297612&fm=11&fmt=auto&gp=0.jpg");
        newsMessage.addNewsArticle(newsArticle);
        newsMessage.addNewsArticle(article);
        String[] url = {"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=bdb9174a-a64d-458e-9e7c-a5bf69a845fc","https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=99586f2c-f8b2-4b0a-92ac-d1367918b3f3"};
        wechatService.send(newsMessage);
        SendResult send =  wechatService.sendUrls(url,newsMessage);
        return send;
    }
    @RequestMapping("/SEND2")
    public SendResult ss2(){
        String string = "https://c-ssl.duitang.com/uploads/blog/202008/22/20200822114634_2b3e0.thumb.1000_0.png";
        ImageBase64Md5 image = Base64Utils.ImageToBase64ByOnline(string);
        ImageMessage imageMessage = new ImageMessage(image.getBase64(),image.getMd5());
        SendResult result = wechatService.send(imageMessage);
        return result;
    }
    @RequestMapping("/SEND3")
    public SendResult ss3(){
        MarkdownMessage message = new MarkdownMessage();
        message.add(MarkdownMessage.getHeaderText(2, MarkdownMessage.getTestColor("有新用户注册啦","warning")));
        message.add(MarkdownMessage.getReferenceText("测试mradow： "+"合伙"));
        message.add(MarkdownMessage.getReferenceText("用户名： "+"test"));
        message.add("\n\n");
        SendResult result = wechatService.send(message);
        return result;
    }
    @RequestMapping("/SEND5")
    public SendResult ss5(MultipartFile[] file){
        SendResult result =null;
                Arrays.stream(file).forEach(res-> {
            FileMessage fileMessage = new FileMessage();
            fileMessage.getFilemedia_id("99586f2c-f8b2-4b0a-92ac-d1367918b3f3",res);
            wechatService.send(fileMessage);
        });
        return result;
    }
}
